/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package boundary.display;

import components.utils.ComponentFactory;
import control.Application;
import entity.Custody;
import entity.Entity;
import entity.Sample;
import entity.Test;
import java.awt.Color;
import java.util.List;
import javax.swing.DefaultListModel;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

/**
 *
 * @author Juan
 */
public class PSampleDisplay extends EntityDisplayPanel {
    
    private DateTimeFormatter formatter = DateTimeFormat.forPattern("dd MMMM yyyy");
    private String dispositionMethod;

    /**
     * Creates new form PSampleDisplay
     */
    public PSampleDisplay() {
        initComponents();
    }

    @Override
    public void setCurrentEntity(Entity entity) throws IllegalArgumentException {
        if (entity instanceof Sample) {
            currentEntity = entity;
            Sample currentSample = (Sample) entity;
            initializeSampleData(currentSample);
            initializeCustodyData(currentSample);
        } else {
            throw new IllegalArgumentException("The object to be displayed is not a Sample.");
        }
    }
    
    private void initializeSampleData(Sample currentSample) {
        TFName.setText(currentSample.getName());
        if (currentSample.isRadioactive()) {
            LRadioactive.setForeground(Color.red);
            LRadioactive.setText("SÍ");
        } else {
            LRadioactive.setText("NO");
        }
        if (currentSample.isMagnetic()) {
            LMagnetic.setText("SÍ");
        } else {
            LMagnetic.setText("NO");
        }
        TFAlphaCode.setText(currentSample.toString());
        formatter = DateTimeFormat.forPattern("dd MMMM yyyy");
        TFRegistrationDate.setText(formatter.print(currentSample.getServiceRequest().getRegistrationDate()));
        TFState.setText((String) Sample.STATES.get(currentSample.getState()));
        TFAmount.setText(currentSample.getQuantity().toString());
        dispositionMethod = (String) Sample.DISPOSITION_METHOD_NAMES.get(currentSample.getDispositionMethod());
        TFDispositionMethod.setText(dispositionMethod);
        if (dispositionMethod.equals("Devolver")) {
            dispositionMethod = "Devolución";
        } else {
            dispositionMethod = "Disposición";
        }
        TPCustody.setTitleAt(2, dispositionMethod);
        TAComments.setText(currentSample.getComments());
        DefaultListModel model = new DefaultListModel();
        List tests = currentSample.getTests();
        for (Object test : tests) {
            model.addElement(test);
        }
        LTests.setModel(model);
    }
    
    private void initializeCustodyData(Sample currentSample) {
        //Custody setup
        LDDState.setText("Estado de " + dispositionMethod.toLowerCase() + ":");
        jLabel25.setText("Fecha de " + dispositionMethod.toLowerCase() + ":");
        BRegisterDisposition.setText("Registrar " + dispositionMethod.toLowerCase());
        
        //Custody status setup
        Custody leftoverDisposal = currentSample.getLeftoverDisposal();
        Custody storage = currentSample.getStorage();
        Custody disposal = currentSample.getDisposal();
        
        if (currentSample.isRadioactive()) {
            if (!disposal.isRegistered() && !leftoverDisposal.isRegistered()) {
                LCustodyStatus.setForeground(Color.red);
                LCustodyStatus.setText("RADIOACTIVA EN CUSTODIA");
            } else {
                LCustodyStatus.setText("Radioactiva dispuesta");
            }
        } else {
            if (disposal.isRegistered()) {
                LCustodyStatus.setText("Dispuesta");
            } else if (storage.isRegistered()) {
                LCustodyStatus.setText("Almacenada");
            } else {
                LCustodyStatus.setText("En análisis");
            }
        }
        
        if (leftoverDisposal.isRegistered()) {
            LLeftoversStatus.setText("Sobrantes devueltos");
            TFLeftoversDispositionDate.setText(formatter.print(leftoverDisposal.getDate()));
            TFLeftoversResponsible.setText(leftoverDisposal.getResponsible().toString());
            TFLeftoversAmount.setText(leftoverDisposal.getAmount().toString());
            TALeftoversComments.setText(leftoverDisposal.getComments());
        } else {
            LLeftoversStatus.setText("Sobrantes en custodia");
            BRegisterLeftoverDisposal.setEnabled(true);
        }
        
        if (storage.isRegistered()) {
            LStorageStatus.setText("Almacenada");
            TFStorageDate.setText(formatter.print(storage.getDate()));
            TFStorageResponsible.setText(storage.getResponsible().toString());
            TFStoredAmount.setText(storage.getAmount().toString());
            TAStorageComments.setText(storage.getComments());
        } else {
            LStorageStatus.setText("No almacenada");
            BRegisterStorage.setEnabled(true);
        }
        
        if (disposal.isRegistered()) {
            LDisposalStatus.setText("Dispuesta");
            TFDispositionDate.setText(formatter.print(disposal.getDate()));
            TFDispositionResponsible.setText(disposal.getResponsible().toString());
            TFDispositionAmount.setText(disposal.getAmount().toString());
            TADispositionComments.setText(disposal.getComments());
        } else {
            LDisposalStatus.setText("No dispuesta");
            BRegisterDisposition.setEnabled(true);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSplitPane1 = new javax.swing.JSplitPane();
        PCustody = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        LCustodyStatus = new javax.swing.JLabel();
        TPCustody = new javax.swing.JTabbedPane();
        PLeftovers = new javax.swing.JPanel();
        jLabel15 = new javax.swing.JLabel();
        LLeftoversStatus = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        TFLeftoversDispositionDate = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        TFLeftoversResponsible = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        TFLeftoversAmount = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        TALeftoversComments = new javax.swing.JTextArea();
        BRegisterLeftoverDisposal = new javax.swing.JButton();
        BGenerateLeftoverLetter = new javax.swing.JButton();
        PStorage = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        LStorageStatus = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        TFStorageDate = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        TFStorageResponsible = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        TFStoredAmount = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        TAStorageComments = new javax.swing.JTextArea();
        BRegisterStorage = new javax.swing.JButton();
        PDisposal = new javax.swing.JPanel();
        LDDState = new javax.swing.JLabel();
        LDisposalStatus = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        TFDispositionDate = new javax.swing.JTextField();
        jLabel26 = new javax.swing.JLabel();
        TFDispositionResponsible = new javax.swing.JTextField();
        jLabel27 = new javax.swing.JLabel();
        TFDispositionAmount = new javax.swing.JTextField();
        jLabel28 = new javax.swing.JLabel();
        jLabel29 = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        TADispositionComments = new javax.swing.JTextArea();
        BRegisterDisposition = new javax.swing.JButton();
        BGenerateDevolutionLetter = new javax.swing.JButton();
        PSampleInfo = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        TAComments = new javax.swing.JTextArea();
        jLabel10 = new javax.swing.JLabel();
        LMagnetic = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        LRadioactive = new javax.swing.JLabel();
        TFAmount = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        LTests = new javax.swing.JList();
        jLabel2 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        TFRegistrationDate = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        TFAlphaCode = new javax.swing.JTextField();
        TFName = new javax.swing.JTextField();
        TFState = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        TFDispositionMethod = new javax.swing.JTextField();
        BClose = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        jSplitPane1.setDividerLocation(400);

        jLabel13.setText("Estado de custodia:");

        LCustodyStatus.setText("jLabel14");

        jLabel15.setText("Estado de los sobrantes:");

        LLeftoversStatus.setText("jLabel16");

        jLabel16.setText("Fecha de devolución:");

        TFLeftoversDispositionDate.setEditable(false);

        jLabel17.setText("Responsable:");

        TFLeftoversResponsible.setEditable(false);

        jLabel18.setText("Cantidad devuelta:");

        TFLeftoversAmount.setEditable(false);

        jLabel19.setText("gramos");

        jLabel20.setText("Comentarios:");

        TALeftoversComments.setEditable(false);
        TALeftoversComments.setColumns(20);
        TALeftoversComments.setRows(5);
        jScrollPane3.setViewportView(TALeftoversComments);

        BRegisterLeftoverDisposal.setText("Registrar devolución de sobrantes");
        BRegisterLeftoverDisposal.setEnabled(false);
        BRegisterLeftoverDisposal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BRegisterLeftoverDisposalActionPerformed(evt);
            }
        });

        BGenerateLeftoverLetter.setText("Generar carta de devolución de sobrantes");
        BGenerateLeftoverLetter.setEnabled(false);

        javax.swing.GroupLayout PLeftoversLayout = new javax.swing.GroupLayout(PLeftovers);
        PLeftovers.setLayout(PLeftoversLayout);
        PLeftoversLayout.setHorizontalGroup(
            PLeftoversLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PLeftoversLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PLeftoversLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(TFLeftoversDispositionDate)
                    .addComponent(TFLeftoversResponsible)
                    .addComponent(jScrollPane3)
                    .addGroup(PLeftoversLayout.createSequentialGroup()
                        .addGroup(PLeftoversLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(PLeftoversLayout.createSequentialGroup()
                                .addComponent(jLabel15)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(LLeftoversStatus))
                            .addComponent(jLabel16)
                            .addComponent(jLabel17)
                            .addComponent(jLabel18)
                            .addGroup(PLeftoversLayout.createSequentialGroup()
                                .addComponent(TFLeftoversAmount, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel19))
                            .addComponent(jLabel20)
                            .addComponent(BRegisterLeftoverDisposal)
                            .addComponent(BGenerateLeftoverLetter))
                        .addGap(0, 68, Short.MAX_VALUE)))
                .addContainerGap())
        );
        PLeftoversLayout.setVerticalGroup(
            PLeftoversLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PLeftoversLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PLeftoversLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(LLeftoversStatus))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel16)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(TFLeftoversDispositionDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel17)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(TFLeftoversResponsible, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel18)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PLeftoversLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TFLeftoversAmount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel19))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel20)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(BRegisterLeftoverDisposal)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(BGenerateLeftoverLetter)
                .addContainerGap(135, Short.MAX_VALUE))
        );

        TPCustody.addTab("Sobrantes", PLeftovers);

        jLabel8.setText("Estado de almacenamiento:");

        LStorageStatus.setText("jLabel9");

        jLabel9.setText("Fecha de almacenamiento:");

        TFStorageDate.setEditable(false);

        jLabel21.setText("Responsable:");

        TFStorageResponsible.setEditable(false);

        jLabel22.setText("Cantidad almacenada:");

        TFStoredAmount.setEditable(false);

        jLabel23.setText("gramos");

        jLabel24.setText("Comentarios:");

        TAStorageComments.setColumns(20);
        TAStorageComments.setRows(5);
        jScrollPane4.setViewportView(TAStorageComments);

        BRegisterStorage.setText("Registrar almacenamiento");
        BRegisterStorage.setEnabled(false);
        BRegisterStorage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BRegisterStorageActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout PStorageLayout = new javax.swing.GroupLayout(PStorage);
        PStorage.setLayout(PStorageLayout);
        PStorageLayout.setHorizontalGroup(
            PStorageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PStorageLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PStorageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(TFStorageDate)
                    .addComponent(TFStorageResponsible)
                    .addComponent(jScrollPane4)
                    .addGroup(PStorageLayout.createSequentialGroup()
                        .addGroup(PStorageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(PStorageLayout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(LStorageStatus))
                            .addComponent(jLabel9)
                            .addComponent(jLabel21)
                            .addComponent(jLabel22)
                            .addGroup(PStorageLayout.createSequentialGroup()
                                .addComponent(TFStoredAmount, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel23))
                            .addComponent(jLabel24)
                            .addComponent(BRegisterStorage))
                        .addGap(0, 117, Short.MAX_VALUE)))
                .addContainerGap())
        );
        PStorageLayout.setVerticalGroup(
            PStorageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PStorageLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PStorageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(LStorageStatus))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(TFStorageDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel21)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(TFStorageResponsible, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel22)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PStorageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TFStoredAmount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel23))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel24)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(BRegisterStorage)
                .addContainerGap(187, Short.MAX_VALUE))
        );

        TPCustody.addTab("Almacenamiento", PStorage);

        LDDState.setText("A");

        LDisposalStatus.setText("jLabel25");

        jLabel25.setText("B");

        TFDispositionDate.setEditable(false);

        jLabel26.setText("Responsable:");

        TFDispositionResponsible.setEditable(false);

        jLabel27.setText("Cantidad:");

        TFDispositionAmount.setEditable(false);

        jLabel28.setText("gramos");

        jLabel29.setText("Comentarios:");

        TADispositionComments.setEditable(false);
        TADispositionComments.setColumns(20);
        TADispositionComments.setRows(5);
        jScrollPane5.setViewportView(TADispositionComments);

        BRegisterDisposition.setText("C");
        BRegisterDisposition.setEnabled(false);
        BRegisterDisposition.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BRegisterDispositionActionPerformed(evt);
            }
        });

        BGenerateDevolutionLetter.setText("Generar carta de devolución de contramuestra");
        BGenerateDevolutionLetter.setEnabled(false);

        javax.swing.GroupLayout PDisposalLayout = new javax.swing.GroupLayout(PDisposal);
        PDisposal.setLayout(PDisposalLayout);
        PDisposalLayout.setHorizontalGroup(
            PDisposalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PDisposalLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PDisposalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(TFDispositionDate)
                    .addComponent(TFDispositionResponsible)
                    .addComponent(jScrollPane5)
                    .addGroup(PDisposalLayout.createSequentialGroup()
                        .addGroup(PDisposalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(PDisposalLayout.createSequentialGroup()
                                .addComponent(LDDState)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(LDisposalStatus))
                            .addComponent(jLabel25)
                            .addComponent(jLabel26)
                            .addComponent(jLabel27)
                            .addGroup(PDisposalLayout.createSequentialGroup()
                                .addComponent(TFDispositionAmount, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel28))
                            .addComponent(jLabel29)
                            .addComponent(BRegisterDisposition)
                            .addComponent(BGenerateDevolutionLetter))
                        .addGap(0, 46, Short.MAX_VALUE)))
                .addContainerGap())
        );
        PDisposalLayout.setVerticalGroup(
            PDisposalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PDisposalLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PDisposalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(LDDState)
                    .addComponent(LDisposalStatus))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel25)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(TFDispositionDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel26)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(TFDispositionResponsible, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel27)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PDisposalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TFDispositionAmount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel28))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel29)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(BRegisterDisposition)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(BGenerateDevolutionLetter)
                .addContainerGap(148, Short.MAX_VALUE))
        );

        TPCustody.addTab("D || D", PDisposal);

        javax.swing.GroupLayout PCustodyLayout = new javax.swing.GroupLayout(PCustody);
        PCustody.setLayout(PCustodyLayout);
        PCustodyLayout.setHorizontalGroup(
            PCustodyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PCustodyLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PCustodyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(TPCustody)
                    .addGroup(PCustodyLayout.createSequentialGroup()
                        .addComponent(jLabel13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(LCustodyStatus)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        PCustodyLayout.setVerticalGroup(
            PCustodyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PCustodyLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PCustodyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(LCustodyStatus))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(TPCustody)
                .addContainerGap())
        );

        jSplitPane1.setRightComponent(PCustody);

        jLabel11.setText("Comentarios:");

        TAComments.setEditable(false);
        TAComments.setColumns(20);
        TAComments.setRows(5);
        jScrollPane1.setViewportView(TAComments);

        jLabel10.setText("Magnética:");

        LMagnetic.setText("jLabel11");

        jLabel7.setText("Radioactiva:");

        LRadioactive.setText("jLabel10");

        TFAmount.setEditable(false);

        jLabel6.setText("gramos");

        LTests.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                LTestsMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(LTests);

        jLabel2.setText("Código Alpha:");

        jLabel12.setText("Análisis:");

        jLabel1.setText("Identificación:");

        jLabel5.setText("Cantidad:");

        TFRegistrationDate.setEditable(false);

        jLabel3.setText("Fecha de Registro:");

        TFAlphaCode.setEditable(false);

        TFName.setEditable(false);

        TFState.setEditable(false);

        jLabel4.setText("Tipo de muestra:");

        jLabel14.setText("Tipo de disposición:");

        TFDispositionMethod.setEditable(false);

        javax.swing.GroupLayout PSampleInfoLayout = new javax.swing.GroupLayout(PSampleInfo);
        PSampleInfo.setLayout(PSampleInfoLayout);
        PSampleInfoLayout.setHorizontalGroup(
            PSampleInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PSampleInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PSampleInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(TFName)
                    .addComponent(TFDispositionMethod)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 379, Short.MAX_VALUE)
                    .addGroup(PSampleInfoLayout.createSequentialGroup()
                        .addGroup(PSampleInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel5)
                            .addGroup(PSampleInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(PSampleInfoLayout.createSequentialGroup()
                                    .addComponent(TFAmount)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jLabel6))
                                .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(TFAlphaCode, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(TFRegistrationDate, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(TFState, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(PSampleInfoLayout.createSequentialGroup()
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(LRadioactive))
                            .addGroup(PSampleInfoLayout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(LMagnetic))
                            .addComponent(jLabel14)
                            .addComponent(jLabel11)
                            .addComponent(jLabel12))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        PSampleInfoLayout.setVerticalGroup(
            PSampleInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PSampleInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(TFName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(PSampleInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(LRadioactive))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(PSampleInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(LMagnetic))
                .addGap(17, 17, 17)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(TFAlphaCode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(TFRegistrationDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(TFState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PSampleInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TFAmount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(TFDispositionMethod, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel12)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jSplitPane1.setLeftComponent(PSampleInfo);

        BClose.setText("Cerrar");
        BClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BCloseActionPerformed(evt);
            }
        });

        jButton1.setText("Imprimir Código");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.Alignment.TRAILING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(BClose)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BClose)
                    .addComponent(jButton1))
                .addGap(0, 9, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void BCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BCloseActionPerformed
        buttonTabComponent.closeTab();
    }//GEN-LAST:event_BCloseActionPerformed

    private void BRegisterLeftoverDisposalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BRegisterLeftoverDisposalActionPerformed
        Sample currentSample = (Sample) currentEntity;
        Custody leftoverDisposal = ComponentFactory.registerLeftoverDisposal(this.getTopLevelAncestor(), currentSample);
        if (leftoverDisposal != null) {
            currentSample.setLeftoverDisposal(leftoverDisposal);
            initializeCustodyData(currentSample);
            BRegisterLeftoverDisposal.setEnabled(false);
            //TODO persist to database
        }
    }//GEN-LAST:event_BRegisterLeftoverDisposalActionPerformed

    private void BRegisterStorageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BRegisterStorageActionPerformed
        Sample currentSample = (Sample) currentEntity;
        Custody storage = ComponentFactory.registerStorage(this.getTopLevelAncestor(), currentSample);
        if (storage != null) {
            currentSample.setStorage(storage);
            initializeCustodyData(currentSample);
            BRegisterStorage.setEnabled(false);
            //TODO persist
        }
    }//GEN-LAST:event_BRegisterStorageActionPerformed

    private void BRegisterDispositionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BRegisterDispositionActionPerformed
        Sample currentSample = (Sample) currentEntity;
        Custody disposal = ComponentFactory.registerDisposal(this.getTopLevelAncestor(), currentSample);
        if (disposal != null) {
            currentSample.setDisposal(disposal);
            initializeCustodyData(currentSample);
            BRegisterDisposition.setEnabled(false);
            //TODO persist
        }
    }//GEN-LAST:event_BRegisterDispositionActionPerformed

    private void LTestsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_LTestsMouseClicked
        if (evt.getClickCount() == 2) {
            Test currentTest = (Test) LTests.getSelectedValue();
            Application.displayEntity(currentTest.getDatabaseTest());
        }
    }//GEN-LAST:event_LTestsMouseClicked

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        control.ControlSample.printBarcode(currentEntity);
    }//GEN-LAST:event_jButton1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BClose;
    private javax.swing.JButton BGenerateDevolutionLetter;
    private javax.swing.JButton BGenerateLeftoverLetter;
    private javax.swing.JButton BRegisterDisposition;
    private javax.swing.JButton BRegisterLeftoverDisposal;
    private javax.swing.JButton BRegisterStorage;
    private javax.swing.JLabel LCustodyStatus;
    private javax.swing.JLabel LDDState;
    private javax.swing.JLabel LDisposalStatus;
    private javax.swing.JLabel LLeftoversStatus;
    private javax.swing.JLabel LMagnetic;
    private javax.swing.JLabel LRadioactive;
    private javax.swing.JLabel LStorageStatus;
    private javax.swing.JList LTests;
    private javax.swing.JPanel PCustody;
    private javax.swing.JPanel PDisposal;
    private javax.swing.JPanel PLeftovers;
    private javax.swing.JPanel PSampleInfo;
    private javax.swing.JPanel PStorage;
    private javax.swing.JTextArea TAComments;
    private javax.swing.JTextArea TADispositionComments;
    private javax.swing.JTextArea TALeftoversComments;
    private javax.swing.JTextArea TAStorageComments;
    private javax.swing.JTextField TFAlphaCode;
    private javax.swing.JTextField TFAmount;
    private javax.swing.JTextField TFDispositionAmount;
    private javax.swing.JTextField TFDispositionDate;
    private javax.swing.JTextField TFDispositionMethod;
    private javax.swing.JTextField TFDispositionResponsible;
    private javax.swing.JTextField TFLeftoversAmount;
    private javax.swing.JTextField TFLeftoversDispositionDate;
    private javax.swing.JTextField TFLeftoversResponsible;
    private javax.swing.JTextField TFName;
    private javax.swing.JTextField TFRegistrationDate;
    private javax.swing.JTextField TFState;
    private javax.swing.JTextField TFStorageDate;
    private javax.swing.JTextField TFStorageResponsible;
    private javax.swing.JTextField TFStoredAmount;
    private javax.swing.JTabbedPane TPCustody;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JSplitPane jSplitPane1;
    // End of variables declaration//GEN-END:variables
}
